package com.spm.librarianmanagersystem.controller;

import com.alibaba.fastjson.JSONObject;
import com.spm.librarianmanagersystem.service.BookCopyService;
import com.spm.librarianmanagersystem.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class BookCopyController {
    @Autowired
    BookCopyService service;

    @DeleteMapping("/api/admin/book/deletecollection")
    public JsonResult<String> deleteCollection(@RequestBody JSONObject request) {
        try {
            String msg = service.deleteCollection(request.getString("ISBN"),
                    request.getInteger("book_id"));
            return new JsonResult<>(0, msg);
        } catch (Exception e) {
            return new JsonResult<>(1, e.getMessage());
        }
    }

    @PostMapping("/api/admin/book/editstatus")
    public JsonResult<Boolean> editStatus(@RequestBody JSONObject obj){
        try{
            Boolean aBoolean = service.editStatus(obj);
            if(aBoolean)
                return new JsonResult<>(true);
            else
                return new JsonResult<>(false, 1, "状态修改失败");

        }catch (Exception e){
            return new JsonResult<>(1,e.getMessage());
        }

    }
}
